package wangxiaotao.converter;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import wangxiaotao.bean.vo.UserVO;
import wangxiaotao.entity.User;

import java.util.Map;

@Mapper(componentModel = "spring")
public interface UserConverter {
    ////默认复制存在的属性

    UserVO toUserVO(User user);

    User toUser(UserVO userVO);

    @Mappings({
            @Mapping(ignore = true,defaultValue = "null",target = "id"),
            @Mapping(expression = "java((String)map.get(\"name\"))", target = "name"),
            @Mapping(expression = "java((Boolean)map.get(\"gender\"))", target = "gender"),
            @Mapping(expression = "java((String)map.get(\"username\"))", target = "username"),
            @Mapping(expression = "java((String)map.get(\"password\"))", target = "password"),
            @Mapping(expression = "java((String)map.get(\"avatar\"))", target = "avatar"),
            @Mapping(expression = "java((String)map.get(\"phone\"))", target = "phone"),
            @Mapping(expression = "java((String)map.get(\"email\"))", target = "email"),
            @Mapping(expression = "java((String)map.get(\"address\"))", target = "address"),
            @Mapping(expression = "java((Integer)map.get(\"loginCount\"))", target = "loginCount"),
            @Mapping(ignore = true,defaultValue = "null",target = "lastLoginTime"),
            @Mapping(ignore = true,defaultValue = "null",target = "createTime"),
            @Mapping(ignore = true,defaultValue = "null",target = "updateTime"),
            @Mapping(ignore = true,defaultValue = "null",target = "isDeleted"),
            @Mapping(ignore = true,defaultValue = "null",target = "statue"),
            @Mapping(ignore = true,defaultValue = "",target = "roleDescs"),
    })
    User toUser(Map<String,Object> map);

}
